<?php
header('Content-type: application/x-javascript');
include_once('auth.php');

function base64url_decode($base64url) {
	$base64 = strtr($base64url, '-_', '+/');
	$plainText = base64_decode($base64);
	return ($plainText);
}
function base64url_encode($plainText) {
	$base64 = base64_encode($plainText);
	$base64url = strtr($base64, '+/', '-_');
	return ($base64url);   
}


$hasmp3s = false;
$ignorevals = array ("Icon","Icon\x0D" ,"index.php", "TheVolumeSettingsFolder");

if (!$MP3_LIBRARY_LOCATION) die("alert('The path to your music collection has not been set in the local_config file.');");

$dir_handle = @opendir($MP3_LIBRARY_LOCATION) or die("alert('Unable to open music directory: $MP3_LIBRARY_LOCATION');");
while ($file = readdir($dir_handle)) {
	$key = strtoupper($file);
	if (substr($key,0,4)=='THE ') $key = substr($key,4);
	while (isset($files[$key])) $key = $key.'_';				//Eliminate cases of "Beach Boys" overwriting "The Beach Boys"

	if ($file{0} != '.' && !in_array($file,$ignorevals)) $files[$key] = $file;
	
}
ksort($files, SORT_STRING);
closedir($dir_handle);

foreach ($files as $stritem) {
	if (!$MUSIKER_DEMOMODE || array_search(strtoupper($stritem), $DEMO_ALLOWEDARTISTS)!==FALSE) {  
		//if the user has logged in with the "demo" account, restrict them to a preset list.
		//otherwise, output all artists
		$outdir = "$MP3_LIBRARY_LOCATION/$stritem";	
		$getdir = base64url_encode($outdir);
		if (is_dir($outdir)) echo "Musiker.modBrowser.artistsByName['",htmlentities($stritem,ENT_QUOTES),"'] = '$getdir';\n";
	}
}

?>
LoadProgress.completeModule('Artists');


